home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  11.4 KB  |  392 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "IntlTest.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef DEFINES_K
  29. #include "Defines.k"
  30. #endif
  31.  
  32. #ifndef VIEW_H
  33. #include "View.h"
  34. #endif
  35.  
  36. #ifndef SELECT_H
  37. #include "Select.h"
  38. #endif
  39.  
  40. #ifndef EDITVIEWS_H
  41. #include "EditViews.h"
  42. #endif
  43.  
  44. // ----- Framework Layer -----
  45.  
  46. #ifndef FWCONTXT_H
  47. #include "FWContxt.h"
  48. #endif
  49.  
  50. #ifndef FWUTIL_H
  51. #include "FWUtil.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWSELECT_H
  59. #include "FWSelect.h"
  60. #endif
  61.  
  62. #ifndef FWEDVIEW_H
  63. #include "FWEdView.h"
  64. #endif
  65.  
  66. #ifndef FWGROWBX_H
  67. #include "FWGrowBx.h"
  68. #endif
  69.  
  70. #ifndef FWIDLE_H
  71. #include "FWIdle.h"
  72. #endif
  73.  
  74. #ifndef FWSCLBAR_H
  75. #include "FWSclBar.h"
  76. #endif
  77.  
  78. #ifndef FWSTATIC_H
  79. #include "FWStatic.h"
  80. #endif
  81.  
  82. #ifndef FWTABBER_H
  83. #include "FWTabber.h"
  84. #endif
  85.  
  86. // ----- OS Layer -----
  87.  
  88. #ifndef FWMENU_H
  89. #include "FWMenu.h"
  90. #endif
  91.  
  92. #ifndef FWEVENT_H
  93. #include "FWEvent.h"
  94. #endif
  95.  
  96. #ifndef FWALERT_H
  97. #include "FWAlert.h"
  98. #endif
  99.  
  100. // ----- Graphic Includes -----
  101.  
  102. #ifndef FWRECT_H
  103. #include "FWRect.h"
  104. #endif
  105.  
  106. #ifndef FWTXTBOX_H
  107. #include "FWTxtBox.h"
  108. #endif
  109.  
  110. #ifndef FWRECSHP_H
  111. #include "FWRecShp.h"
  112. #endif
  113.  
  114. // ----- OpenDoc Includes -----
  115.  
  116. #ifndef SOM_Module_OpenDoc_StdProps_defined
  117. #include <StdProps.xh>
  118. #endif
  119.  
  120. #ifndef SOM_ODDragItemIterator_xh
  121. #include <DgItmIt.xh>
  122. #endif
  123.  
  124. //========================================================================================
  125. // Runtime Information
  126. //========================================================================================
  127.  
  128. #ifdef FW_BUILD_MAC
  129. #pragma segment odfIntlTest
  130. #endif
  131.  
  132. //========================================================================================
  133. // CIntlTestFrame class
  134. //========================================================================================
  135.  
  136. FW_DEFINE_AUTO(CIntlTestFrame)
  137.  
  138. //----------------------------------------------------------------------------------------
  139. // CIntlTestFrame constructor
  140. //----------------------------------------------------------------------------------------
  141. CIntlTestFrame::CIntlTestFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CIntlTestPart* part) :
  142.     FW_CFrame(ev, odFrame, presentation, part),
  143.     FW_MDroppableFrame(ev, this),
  144.     FW_MReceiver(),
  145.     fTestPart(part),
  146.     fTestView(NULL),
  147.     fTestSelection((CIntlTestSelection*)presentation->GetSelection(ev)),
  148.     fViewTabber(NULL)
  149. {
  150.     FW_CIdler* idler = FW_NEW(FW_CIdler, (this, 15));
  151.     idler->RegisterIdle(ev);                
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // CIntlTestFrame destructor
  156. //----------------------------------------------------------------------------------------
  157.  
  158. CIntlTestFrame::~CIntlTestFrame()
  159. {
  160.     // fViewTabber is deleted automatically because it's an attached event handler
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    CIntlTestFrame::CanAcceptDrop
  165. //----------------------------------------------------------------------------------------
  166.  
  167. ODDragResult CIntlTestFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  168. {
  169.     ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
  170.  
  171.     // ----- Test for 'TEXT' also -----
  172. #ifdef FW_BUILD_MAC
  173.     if (!acceptDrop)
  174.     {
  175.         for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  176.             if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0))    // 'TEXT' on Scrap
  177.                 return TRUE;
  178.     }
  179. #endif
  180.  
  181.     return acceptDrop;
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. // CIntlTestFrame::Draw
  186. //----------------------------------------------------------------------------------------
  187.  
  188. void CIntlTestFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  189. {
  190.     FW_CRect frameRect = GetBounds(ev);
  191.     FW_CRect centerRect(GetFrame(ev)->GetContentView(ev)->GetBounds(ev));
  192.     
  193.     // Draw a gray background around the content view if it's smaller
  194.     if (centerRect.right < frameRect.right || centerRect.bottom < frameRect.bottom ) {
  195.  
  196.         FW_CViewContext vc(ev, this, odFacet, invalidShape);
  197.     
  198.         // Draw outside the center view to avoid flashing 
  199.         FW_CAcquiredODShape aqPaneShape = ::FW_NewODShape(ev, frameRect);
  200.         FW_CAcquiredODShape aqCenterShape = ::FW_NewODShape(ev, centerRect);
  201.         aqPaneShape->Subtract(ev, aqCenterShape);
  202.     
  203.         FW_CRegionShape::RenderRegion(vc, aqPaneShape, FW_kFill, FW_kRGBLightGray);
  204.     
  205.         // Draw a shadow frame around the content view
  206.         centerRect.Inset(-FW_IntToFixed(1),-FW_IntToFixed(1));
  207.          FW_CRectShape::RenderRect(vc, centerRect, FW_kFrame);
  208.          FW_CPoint p1(centerRect.left, centerRect.bottom);
  209.          FW_CPoint p2(centerRect.right, centerRect.bottom);
  210.          FW_CPoint p3(centerRect.right, centerRect.top);
  211.          FW_CLineShape::RenderLine(vc, p1, p2);
  212.          FW_CLineShape::RenderLine(vc, p2, p3);
  213.      }
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    CIntlTestFrame::NewClipboardCommand
  218. //----------------------------------------------------------------------------------------
  219.  
  220. FW_CClipboardCommand* CIntlTestFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  221. {
  222.     FW_CEditView* editView = NULL;
  223.     ODID id = this->GetActiveEditViewId(ev);
  224.     if (id)
  225.     {
  226.         editView = this->FindEditView(ev, id);
  227.     }
  228.  
  229.     CIntlTestEditCommand* cmd = FW_NEW(CIntlTestEditCommand, (ev, commandID, this, fTestSelection, editView, FW_kCanUndo));
  230.     return cmd;
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    CIntlTestFrame::NewDropCommand
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_CDropCommand* CIntlTestFrame::NewDropCommand(Environment* ev,
  238.                                                 FW_CFrame* frame,
  239.                                                 ODDragItemIterator* dropInfo, 
  240.                                                 ODFacet* odFacet, 
  241.                                                 const FW_CPoint& dropPoint)
  242. {
  243.     FW_CEditView* dropView = this->HitTest(ev, dropPoint);
  244.     if (dropView)
  245.         return FW_NEW(CIntlTestDropCommand, (ev, this, dropView, fTestSelection, dropInfo, odFacet, dropPoint));
  246.  
  247.     // dropPoint isn't in an edit view
  248.     return NULL;
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. //    CIntlTestFrame::CreateSubViews
  253. //----------------------------------------------------------------------------------------
  254. void CIntlTestFrame::CreateSubViews(Environment* ev)
  255. {        
  256.     FW_CFont helvetica(FW_kHelvetica, FW_kPlain, FW_IntToFixed(12));
  257.  
  258.     FW_CRect viewRect;        // working rect for creating the views
  259.     FW_CRect frameRect = GetBounds(ev);
  260.     FW_CPoint extent;
  261.     FW_CRect contentRect;
  262.     GetContentRect(ev, contentRect, extent);
  263.     
  264.     // ----- Create the GrowBox only in root frame
  265.     if (this->IsRoot(ev)) 
  266.     {
  267.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, contentRect.BotRight());
  268.     }
  269.     else
  270.     {
  271.         // Leave space to draw 1 pixel border in non-root frames
  272.         frameRect.Inset(FW_kFixedPos1);
  273.     }
  274.  
  275.     // ----- Create the content view
  276.     CIntlTestView* contentView = new CIntlTestView(ev, this, contentRect, extent);
  277.     contentView->MakeContentView(ev);
  278.     fTestView = contentView;
  279.     
  280.     // ---- Create the static texts
  281.     viewRect.Set(FW_IntToFixed(10), FW_IntToFixed(10), FW_IntToFixed(150), FW_IntToFixed(30));
  282.     FW_CStaticText* staticText1 = FW_NEW(FW_CStaticText, (ev, this, viewRect, FW_CString("Type here:")));
  283.  
  284.     viewRect.Set(FW_IntToFixed(160), FW_IntToFixed(10), FW_IntToFixed(300), FW_IntToFixed(30));
  285.     FW_CStaticText* staticText2 = FW_NEW(FW_CStaticText, (ev, this, viewRect, FW_CString("ì¸óÕǵǃÇ≠ÇæÇ≥Ç¢ÅF"), gFontOsaka));
  286.  
  287.     // ----- Create the EditViews
  288.     unsigned short attributes = FW_CEditView::kDrawBox + FW_CEditView::kAutoScroll;
  289.      /* Set(L, T, R, B) */
  290.  
  291.     viewRect.Set(FW_IntToFixed(10), FW_IntToFixed(40), FW_IntToFixed(150), FW_IntToFixed(60));    
  292.     CMyEditView* editView1 = FW_NEW(CMyEditView, (ev, contentView, kEnglishEditView, viewRect, helvetica, 32, attributes));
  293.  
  294.     viewRect.Set(FW_IntToFixed(160), FW_IntToFixed(40), FW_IntToFixed(300), FW_IntToFixed(60));    
  295.     CJapEditView* editView2 = FW_NEW(CJapEditView, (ev, contentView, kJapaneseEditView, viewRect, gFontOsaka, 32, 
  296.                                         attributes + FW_CEditView::kInlineInput + FW_CEditView::kTextServices));
  297.     editView2->InitJapEditView(ev);
  298.  
  299.     attributes = FW_CEditView::kDrawBox + FW_CEditView::kWordWrap;    // no autoscroll for this view
  300.     viewRect.Set(FW_IntToFixed(10), FW_IntToFixed(80), FW_IntToFixed(300), FW_IntToFixed(240));    
  301.     CMyEditView* editView3 = FW_NEW(CMyEditView, (ev, contentView, kTextEditView, viewRect, helvetica, 500, attributes));
  302.  
  303.     // ----- Tell edit views to notify the frame when something noteworthy occurs -----
  304.     editView1->LinkToReceiver(this);
  305.     editView2->LinkToReceiver(this);
  306.     editView3->LinkToReceiver(this);
  307.  
  308.     // ----- Add a ViewTabber to the frame 
  309.     fViewTabber = new FW_CViewTabber(ev, this); 
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. ODID CIntlTestFrame::GetActiveEditViewId(Environment* ev)
  314. {
  315.     FW_MEventHandler* target = this->GetTarget(ev);
  316.     if (target)
  317.     {
  318.         FW_CView* targetView = FW_DYNAMIC_CAST(FW_CView, target);
  319.         if (targetView)
  320.             return targetView->GetViewId(ev);
  321.     }
  322.  
  323.     return 0;
  324. }
  325.  
  326. //----------------------------------------------------------------------------------------
  327. FW_CEditView* CIntlTestFrame::FindEditView(Environment* ev, ODID id)
  328. {
  329.     return (FW_CEditView*) fTestView->FindViewById(ev, id);
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. void CIntlTestFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  334. {
  335.     FW_CFrame::FacetAdded(ev, facet, facetCount);    // Call inherited
  336.  
  337.     // Perform "DoPostCreate"-type initialization here.
  338.     fTestPart->UpdateViewsFromTextData(ev);
  339. }
  340.  
  341. //----------------------------------------------------------------------------------------
  342. void CIntlTestFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  343. {
  344.     // ---- Handle notification messages from the edit views
  345.     if (notification.GetMessage() == kEditViewMsg)
  346.     {
  347.         fTestPart->Changed(ev);    // so we can Save
  348.     }
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. void CIntlTestFrame::GetContentRect(Environment* ev, FW_CRect& rect, FW_CPoint& extent)
  353. {
  354.     rect = GetBounds(ev);
  355.     
  356.     // Leave space to draw 1 pixel border in non-root frames
  357.     if (IsRoot(ev) == FALSE)
  358.         rect.Inset(FW_kFixedPos1);
  359.  
  360.     extent = rect.BotRight();
  361.  
  362.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  363.     rect.right -= sbSize.x;
  364.     rect.bottom -= sbSize.y;
  365. }
  366.  
  367. //----------------------------------------------------------------------------------------
  368. FW_CEditView* CIntlTestFrame::HitTest(Environment* ev, const FW_CPoint& where)
  369. {
  370.     // Find out which edit view the point is in; return NULL if point is not in an edit view.
  371.     FW_CEditView* editView;
  372.     FW_CRect bounds;
  373.  
  374.     editView = this->FindEditView(ev, kTextEditView);
  375.     bounds = editView->GetBounds(ev);
  376.     if (bounds.Contains(where))
  377.         return editView;
  378.  
  379.     editView = this->FindEditView(ev, kJapaneseEditView);
  380.     bounds = editView->GetBounds(ev);
  381.     if (bounds.Contains(where))
  382.         return editView;
  383.  
  384.     editView = this->FindEditView(ev, kEnglishEditView);
  385.     bounds = editView->GetBounds(ev);
  386.     if (bounds.Contains(where))
  387.         return editView;
  388.  
  389.     return NULL;
  390. }
  391.  
  392.